package yui.bss.demo.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yui.bss.demo.mgr.SysLinkMgr;
import yui.bss.demo.ro.LinkRo;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统用户
 * </p>
 *
 * @author yui
 */
@Api(value="系统连接")
@RestController
@RequestMapping("/sys/link")
public class SysLinkController extends BaseController {
    @Autowired
    private SysLinkMgr sysLinkMgr;


//    @ApiOperation(value = "列表查询")
//    @GetMapping("upd2")
//    public Object upd2(String query) {
//
//        return build(mapIPage);
//    }

    @ApiOperation(value = "查询")
    @PostMapping("selectLink")
    public Object selectLink(@RequestBody LinkRo linkRo) {
        String sql = linkRo.getDecryptLink();
        List<Map<String, Object>> list = sysLinkMgr.selectLink(sql);
        return build(list);
    }

    @ApiOperation(value = "新增")
    @PostMapping("insertLink")
    public Object insertLink(@RequestBody LinkRo linkRo) {
        String sql = linkRo.getDecryptLink();
        int ret = sysLinkMgr.updateLink(sql);
        return build(ret);
    }

    @ApiOperation(value = "更新")
    @PostMapping("updateLink")
    public Object updateLink(@RequestBody LinkRo linkRo) {
        String sql = linkRo.getDecryptLink();
        int ret = sysLinkMgr.updateLink(sql);
        return build(ret);
    }

    @ApiOperation(value = "更新")
    @PostMapping("deleteLink")
    public Object deleteLink(@RequestBody LinkRo linkRo) {
        String sql = linkRo.getDecryptLink();
        int ret = sysLinkMgr.deleteLink(sql);
        return build(ret);
    }

    @ApiOperation(value = "查询")
    @PostMapping("selectLinkDemo")
    public Object selectLinkDemo() {
        StringBuffer sqlBuf = new StringBuffer();
        sqlBuf.append("select b.* from t_sys_user a, t_sys_role b where a.id = b.id");
        List<Map<String, Object>> list = sysLinkMgr.selectLink(sqlBuf.toString());
        return build(list);
    }

    @ApiOperation(value = "新增")
    @PostMapping("insertLinkDemo")
    public Object insertLinkDemo() {
        StringBuffer sqlBuf = new StringBuffer();
        sqlBuf.append("insert t_sys_user(id, username) values ('1234', '1234')");
        int ret = sysLinkMgr.updateLink(sqlBuf.toString());
        return build(ret);
    }

    @ApiOperation(value = "更新")
    @PostMapping("updateLinkDemo")
    public Object updateLinkDemo() {
        StringBuffer sqlBuf = new StringBuffer();
        sqlBuf.append("update t_sys_user set username = 'oio' where id = 1 ");
        int ret = sysLinkMgr.updateLink(sqlBuf.toString());
        return build(ret);
    }

    @ApiOperation(value = "更新")
    @PostMapping("deleteLinkDemo")
    public Object deleteLinkDemo() {
        StringBuffer sqlBuf = new StringBuffer();
        sqlBuf.append("delete from t_sys_user where id = 12");
        int ret = sysLinkMgr.deleteLink(sqlBuf.toString());
        return build(ret);
    }

}